﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonTagTime;
using CommonTagTime.Business;
using CommonTagTime.ModelObject;
using CommonTagTime.PagerControl;
public partial class StepByStep : SitePage
{
   
    protected override void OnInit(EventArgs e)
    {
        InitData();
        base.OnInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            LoadData();
    }
    protected void dalStepByStep_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        DataListItem item = e.Item;
        TipNews data = new TipNews();
        if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
        {
            if (data == null)
                return;
            data = (TipNews)item.DataItem;
            PlaceHolder phdControl = (PlaceHolder)item.FindControl("phdControlStepByStep");
            UserControl ctrl = new UserControl();
            UserControl_StepByStepItem uc = (UserControl_StepByStepItem)ctrl.LoadControl("~/UserControl/StepByStepItem.ascx");
            if (uc != null)
            {
                uc.objTip = data;
            }
            phdControl.Controls.Add(uc);
        }
    }
    protected void pagerTop_PageIndexChanging(object obj, CommonTagTime.PagerControl.PageIndexChangeEventArgs e)
    {
        this.pagerTop.PageIndex=this.pagerBottom.PageIndex = e.PageIndex;
        LoadData();
    }
    protected void pagerTop_PageSizeChanging(object obj, CommonTagTime.PagerControl.PageSizeChangeEventArgs e)
    {
        this.pagerTop.PageIndex = this.pagerBottom.PageIndex = 1;
        pagerBottom.PageSize = pagerTop.PageSize = e.PageSize;
        LoadData();
    }
    private void LoadData()
    {
        TipNewsCollection lstResult = new TipNewsCollection();
        busTipNews objBus = new busTipNews();
        //get Condition
        TipNews objTipNews = new TipNews();
        objTipNews.CurrentPage = this.pagerTop.PageIndex;
        objTipNews.OrderBy = busTipNews.SORTORDER;
        objTipNews.OrderDirection = "ASC";
        objTipNews.PageSize = pagerTop.PageSize;
        objTipNews.Condition = " t.IsActive=1 and t.[Type]='" + (int)enmTipNewsType.Tip + "'";
        lstResult = objBus.List(objTipNews);
        int count = 0;
        if (lstResult != null && lstResult.Count > 0)
        {
            count = lstResult.Count;
            dalStepByStep.DataSource = lstResult;
            dalStepByStep.DataBind();
            pagerTop.SetPaging(count, objTipNews.TotalRecords);
            pagerBottom.SetPaging(count, objTipNews.TotalRecords);
            pagerTop.Visible = true;
            pagerBottom.Visible = true;
        }
        else
        {
            pagerTop.Visible = false;
            pagerBottom.Visible = false;
        }

    }
    private void InitData()
    {
        this.pagerTop.PageIndex = this.pagerBottom.PageIndex = 1;
        this.pagerTop.PageSize = this.pagerBottom.PageSize = clsConfigData.DEFAULT_STEPBYSTEP_PAGE_SIZE;
        this.Page.Header.Title = string.Format(Resources.Resource.TITLE,"Step By Step");
    }
}